package com.yuan.sys.modular.driver.controller;


import com.yuan.core.annotion.BusinessLog;
import com.yuan.core.annotion.Permission;
import com.yuan.core.enums.LogAnnotionOpTypeEnum;
import com.yuan.core.pojo.page.PageResult;
import com.yuan.core.pojo.response.ResponseData;
import com.yuan.core.pojo.response.SuccessResponseData;
import com.yuan.sys.modular.driver.param.SysDriverParam;
import com.yuan.sys.modular.driver.result.SysDriverResult;
import com.yuan.sys.modular.driver.service.SysDriverService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author hongawen
 * @version 1.0.0
 * @date 2021年10月21日 21:40
 */
@Controller
@RequiredArgsConstructor
public class SysDriverController {

    private final SysDriverService sysDriverService;

    /**
     * 驾驶员页面
     */
    @Permission
    @GetMapping("/sysDriver/index")
    public String index() {
        return "system/sysDriver/index.html";
    }

    /**
     * 驾驶员表单页面
     */
    @GetMapping("/sysDriver/form")
    public String form() {
        return "system/sysDriver/form.html";
    }



    /**
     * 查询驾驶员
     */
    @Permission
    @ResponseBody
    @GetMapping("/sysDriver/page")
    @BusinessLog(title = "驾驶员_查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public PageResult<SysDriverResult> page(SysDriverParam sysDriverParam) {
        return sysDriverService.page(sysDriverParam);
    }



    /**
     * 导出驾驶员
     */
    @Permission
    @ResponseBody
    @GetMapping("/sysDriver/export")
    @BusinessLog(title = "驾驶员_导出", opType = LogAnnotionOpTypeEnum.EXPORT)
    public void export(SysDriverParam sysDriverParam) {
        sysDriverService.export(sysDriverParam);
    }

    /**
     * 删除驾驶员
     */
    @Permission
    @ResponseBody
    @PostMapping("/sysDriver/delete")
    @BusinessLog(title = "驾驶员_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(SysDriverParam.delete.class) List<SysDriverParam> sysDriverParamList) {
        sysDriverService.delete(sysDriverParamList);
        return new SuccessResponseData();
    }

    /**
     * 编辑驾驶员
     */
    @Permission
    @ResponseBody
    @PostMapping("/sysDriver/edit")
    @BusinessLog(title = "驾驶员_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(SysDriverParam.edit.class) SysDriverParam sysDriverParam) {
        sysDriverService.edit(sysDriverParam);
        return new SuccessResponseData();
    }

    /**
     * 增加驾驶员
     */
    @Permission
    @ResponseBody
    @PostMapping("/sysDriver/add")
    @BusinessLog(title = "驾驶员_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated(SysDriverParam.add.class) SysDriverParam sysDriverParam) {
        sysDriverService.add(sysDriverParam);
        return new SuccessResponseData();
    }

    /**
     * 修改驾驶员状态
     *
     */
    @Permission
    @ResponseBody
    @PostMapping("/sysDriver/changeStatus")
    @BusinessLog(title = "驾驶员_修改状态", opType = LogAnnotionOpTypeEnum.CHANGE_STATUS)
    public ResponseData changeStatus(@RequestBody @Validated(SysDriverParam.changeStatus.class) SysDriverParam sysDriverParam) {
        sysDriverService.changeStatus(sysDriverParam);
        return new SuccessResponseData();
    }


}
